#include<iostream>
#include<string>
#include"cpp-httplib/httplib.h"
#include"Searcher.hpp"

const std::string root_path="./wwwroot";
const std::string input="./raw_html/raw.txt";

int main()
{
    httplib::Server ser;
    ns_searcher::Searcher search;
    search.InitSearcher(input);
    ser.set_base_dir(root_path.c_str());
    ser.Get("/hi",[&search](const httplib::Request &rqs,httplib::Response &rps){
       if(!rqs.has_param("word"))
       {
        rps.set_content("必须输入搜索参数 ","text/plain;charset=utf-8");
        return;
       }
       std::string word=rqs.get_param_value("word");
       std::cout<<"用户正在搜索："<<word<<std::endl;
       std::string json_string;
       search.Search(word,&json_string);
       rps.set_content(json_string,"application/json");
    });

    ser.listen("0.0.0.0" ,8080);

    return 0;
}